package com.crl.utils.color
{
	import com.crl.ui.controls.Component;
	
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.ui.Mouse;
	
	public class AbstractMixer extends Component
	{
		protected var colors:Array
		protected var alphas:Array;
		
		protected var ratios:Array;
		
		protected var _color:Number=0x990000;
		
		protected var mark:Shape;
		
		internal var pointer:Shape;
		
		protected var w:int=50;
		protected var h:int=50;
		
		public function AbstractMixer()
		{
		}
		
		override protected function create():void{
			pointer=new Shape();
			mark=new Shape();
			
			this.addChild(mark);
			this.addChild(pointer);
		}
		
		
		override protected function bind():void{
			this.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
			this.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
		}
		
		
		protected function mouseUpHandler(event:MouseEvent):void{
			Mouse.show();
			
			stage.removeEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
			stage.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
		}
		
		protected function mouseDownHandler(event:MouseEvent):void{
			Mouse.hide();
			
			update(event.localX,event.localY);
			
			stage.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
			stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
		}
		
		protected function mouseMoveHandler(event:MouseEvent):void{
			update(Math.min(this.w,Math.max(0,mouseX)),Math.min(this.h,Math.max(0,mouseY)));
			
			event.updateAfterEvent();
		}
		
		
		
		protected function update(x:int,y:int):void{
			this.pointer.x=x;
			this.pointer.y=y;
			this.dispatchEvent(new Event(Event.CHANGE));
		}
		
		
		override protected function draw():void{
			//画个小圈,利用重复绘制的挖空功能, 画出空心带白底的小圆;
			var g:Graphics=pointer.graphics;
			g.beginFill(0);
			g.drawCircle(0,0,5);
			g.drawCircle(0,0,4);
			g.endFill();
			
			g.beginFill(0xFFFFFF, 1);
			g.drawCircle(0,0,4);
			g.drawCircle(0,0,3);
			g.endFill();
		}
		
		
		
		override public function resize(w:int,h:int):void{
			
			this.w=w;
			this.h=h;
			
			this.invalidate();
		}
	}
}